package com.concurrent.chapter5.concurrent02;

import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Main {
	FutureTask task;
	public static void main(String[] args) {
		try {
			User user = new User();
			MyRunnable myRunnable = new MyRunnable(user);
			int corePoolSize = 10;
			int maximumPoolSize = 10;
			int keepAliveTime = 10;
			TimeUnit unit = TimeUnit.SECONDS;
			LinkedBlockingDeque<Runnable> workQueue = new LinkedBlockingDeque<>();
			ThreadPoolExecutor executor = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue);
			Future<User> future = executor.submit(myRunnable, user);
			System.out.println(System.currentTimeMillis());
			System.out.println(user.getUsername() + "-" + user.getPassword());
			user = future.get();
			System.out.println(user.getUsername() + "-" + user.getPassword());
			System.out.println(System.currentTimeMillis());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
